﻿/********************************************************************************
     File:																
            Manager.aspx.cs                         
     Description:
            商业资讯管理
     Author:									
            DDBuildTools
            http://DDBuildTools.supesoft.com
     Finish DateTime:
            2011-7-21 22:27:38
     History:
*********************************************************************************/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using BingZi.HY.Core.WebControls;

using BingZi.HY.Core.Entities.Center;
using BingZi.HY.Core.Message;
using BingZi.HY.Core;
using BingZi.HY.Core.Enums;
using BingZi.HY.Core.BLL;

namespace BingZi.HY.UI.app_ArticlesUI
{
    public partial class Manager : BingZi.HY.Core.BLL.PageBase
    {
        Int32 IDX = (Int32)BingZi.HY.Core.Common.sink("IDX", BingZi.HY.Core.Enums.MethodType.Get, 10, 0, DataType.Int);
        string CMD = (string)BingZi.HY.Core.Common.sink("CMD", BingZi.HY.Core.Enums.MethodType.Get, 10, 1, DataType.Str);
        protected void Page_Load(object sender, EventArgs e)
        {

            CheckPagePermission(CMD);
            if (!Page.IsPostBack)
            {
                OnStart();
            }
        }

        /// <summary>
        /// 开始操作
        /// </summary>
        private void OnStart()
        {
            app_Articles ut = app_Articles.FindByKeyForEdit(IDX);
            OnStartData(ut);
            switch (CMD)
            {
                case "New":
                    TabOptionItem1.Tab_Name = HeadMenuWebControls1.HeadOPTxt = "增加商业资讯";
                    Hidden_Disp();
                    break;
                case "List":
                    TabOptionItem1.Tab_Name = HeadMenuWebControls1.HeadOPTxt = "查看商业资讯";
                    Hidden_Input();
                    ButtonOption.Visible = false;
                    AddEditButton();
                    break;
                case "Edit":
                    TabOptionItem1.Tab_Name = HeadMenuWebControls1.HeadOPTxt = "修改商业资讯";
                    Hidden_Disp();
                    AddDeleteButton();
                    break;
                case "Delete":

                    if (ut.Delete() > 0)
                    {
                        EventMessage.MessageBox(1, "删除成功", string.Format("删除ID:{0}成功!", IDX), Icon_Type.OK, Common.GetHomeBaseUrl("Default.aspx"));
                    }
                    else
                    {
                        EventMessage.MessageBox(1, "删除失败", string.Format("删除ID:{0}失败!", IDX), Icon_Type.Error, Common.GetHomeBaseUrl("Default.aspx"));
                    }
                    break;
                default:
                    EventMessage.MessageBox(2, "不存在操作字符串!", "不存在操作字符串!", Icon_Type.Error, Common.GetHomeBaseUrl("Default.aspx"));
                    break;
            }
        }

        /// <summary>
        /// 增加修改按钮
        /// </summary>
        private void AddEditButton()
        {
            HeadMenuButtonItem bi = new HeadMenuButtonItem();
            bi.ButtonPopedom = NewLife.CommonEntity.PermissionFlags.Edit;
            bi.ButtonName = "商业资讯";
            bi.ButtonUrl = string.Format("?CMD=Edit&IDX={0}", IDX);
            HeadMenuWebControls1.ButtonList.Add(bi);
        }


        /// <summary>
        /// 增加删除按钮
        /// </summary>
        private void AddDeleteButton()
        {
            HeadMenuButtonItem bi = new HeadMenuButtonItem();
            bi.ButtonPopedom = NewLife.CommonEntity.PermissionFlags.Delete;
            bi.ButtonName = "商业资讯";
            bi.ButtonUrlType = UrlType.JavaScript;
            bi.ButtonUrl = string.Format("DelData('?CMD=Delete&IDX={0}')", IDX);
            HeadMenuWebControls1.ButtonList.Add(bi);

            HeadMenuButtonItem bi1 = new HeadMenuButtonItem();
            bi1.ButtonPopedom = NewLife.CommonEntity.PermissionFlags.List;
            bi1.ButtonIcon = "back.gif";
            bi1.ButtonName = "返回";
            bi1.ButtonUrl = string.Format("?CMD=List&IDX={0}", IDX);
            HeadMenuWebControls1.ButtonList.Add(bi1);
        }

        /// <summary>
        /// 初始化数据
        /// </summary>
        /// <param name="ut"></param>
        private void OnStartData(app_Articles ut)
        {
            UserID_Input.Text = UserID_Disp.Text = ut.UserID.ToString();
            ShopCategoryID_Input.Text = ShopCategoryID_Disp.Text = ut.ShopCategoryID.ToString();
            CategoryID_Input.Text = CategoryID_Disp.Text = ut.CategoryID.ToString();
            A_Title_Input.Text = A_Title_Disp.Text = ut.A_Title.ToString();
            A_Tags_Input.Text = A_Tags_Disp.Text = ut.A_Tags.ToString();
            A_Photo_Input.Text = A_Photo_Disp.Text = ut.A_Photo.ToString();
            A_Description_Input.Text = A_Description_Disp.Text = ut.A_Description.ToString();
            A_StartTime_Input.Text = A_StartTime_Disp.Text = ut.A_StartTime.ToString();
            A_LastTime_Input.Text = A_LastTime_Disp.Text = ut.A_LastTime.ToString();
            A_LastUserID_Input.Text = A_LastUserID_Disp.Text = ut.A_LastUserID.ToString();
            A_Recommended_Input.Text = A_Recommended_Disp.Text = ut.A_Recommended.ToString();
            A_State_Input.Text = A_State_Disp.Text = ut.A_State.ToString();

        }

        /// <summary>
        /// 隐藏输入框
        /// </summary>
        private void Hidden_Input()
        {
            UserID_Input.Visible = false;
            ShopCategoryID_Input.Visible = false;
            CategoryID_Input.Visible = false;
            A_Title_Input.Visible = false;
            A_Tags_Input.Visible = false;
            A_Photo_Input.Visible = false;
            A_Description_Input.Visible = false;
            A_StartTime_Input.Visible = false;
            A_LastTime_Input.Visible = false;
            A_LastUserID_Input.Visible = false;
            A_Recommended_Input.Visible = false;
            A_State_Input.Visible = false;

        }

        /// <summary>
        /// 隐藏显示框
        /// </summary>
        private void Hidden_Disp()
        {
            UserID_Disp.Visible = false;
            ShopCategoryID_Disp.Visible = false;
            CategoryID_Disp.Visible = false;
            A_Title_Disp.Visible = false;
            A_Tags_Disp.Visible = false;
            A_Photo_Disp.Visible = false;
            A_Description_Disp.Visible = false;
            A_StartTime_Disp.Visible = false;
            A_LastTime_Disp.Visible = false;
            A_LastUserID_Disp.Visible = false;
            A_Recommended_Disp.Visible = false;
            A_State_Disp.Visible = false;

        }

        /// <summary>
        /// 增加/修改事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button1_Click(object sender, EventArgs e)
        {

            int UserID_Value = (int)BingZi.HY.Core.Common.sink(UserID_Input.UniqueID, MethodType.Post, 10, 1, DataType.Int);
            int ShopCategoryID_Value = (int)BingZi.HY.Core.Common.sink(ShopCategoryID_Input.UniqueID, MethodType.Post, 10, 1, DataType.Int);
            int CategoryID_Value = (int)BingZi.HY.Core.Common.sink(CategoryID_Input.UniqueID, MethodType.Post, 10, 1, DataType.Int);
            string A_Title_Value = (string)BingZi.HY.Core.Common.sink(A_Title_Input.UniqueID, MethodType.Post, 128, 1, DataType.Str);
            string A_Tags_Value = (string)BingZi.HY.Core.Common.sink(A_Tags_Input.UniqueID, MethodType.Post, 50, 0, DataType.Str);
            string A_Photo_Value = (string)BingZi.HY.Core.Common.sink(A_Photo_Input.UniqueID, MethodType.Post, 128, 0, DataType.Str);
            string A_Description_Value = (string)BingZi.HY.Core.Common.sink(A_Description_Input.UniqueID, MethodType.Post, 2147483647, 1, DataType.Str);
            DateTime A_StartTime_Value = (DateTime)BingZi.HY.Core.Common.sink(A_StartTime_Input.UniqueID, MethodType.Post, 20, 1, DataType.Dat);
            DateTime A_LastTime_Value = (DateTime)BingZi.HY.Core.Common.sink(A_LastTime_Input.UniqueID, MethodType.Post, 20, 1, DataType.Dat);
            int A_LastUserID_Value = (int)BingZi.HY.Core.Common.sink(A_LastUserID_Input.UniqueID, MethodType.Post, 10, 1, DataType.Int);
            int A_Recommended_Value = (int)BingZi.HY.Core.Common.sink(A_Recommended_Input.UniqueID, MethodType.Post, 3, 1, DataType.Int);
            int A_State_Value = (int)BingZi.HY.Core.Common.sink(A_State_Input.UniqueID, MethodType.Post, 3, 1, DataType.Int);
            app_Articles ut = app_Articles.FindByKeyForEdit(IDX); //*.FindByKeyForEdit(IDX);

            ut.UserID = UserID_Value;
            ut.ShopCategoryID = ShopCategoryID_Value;
            ut.CategoryID = CategoryID_Value;
            ut.A_Title = A_Title_Value;
            ut.A_Tags = A_Tags_Value;
            ut.A_Photo = A_Photo_Value;
            ut.A_Description = A_Description_Value;
            ut.A_StartTime = A_StartTime_Value;
            ut.A_LastTime = A_LastTime_Value;
            ut.A_LastUserID = A_LastUserID_Value;
            ut.A_Recommended = A_Recommended_Value;
            ut.A_State = A_State_Value;

            Int32 rInt =  0;
             if (CMD == "New")
            {
                string title= ut.A_Title;
                for (int i = 0; i < 10000; i++)
                {
                    ut.A_Title = title + i.ToString();
                    rInt = ut.Insert();
                }
    
               
               
            }
            else if (CMD == "Edit")
            {
                rInt = ut.Update();
                
                // rInt = ut.Update();
            }
            else
            {
                EventMessage.MessageBox(2, "不存在操作字符串!", "不存在操作字符串!", Icon_Type.Error, Common.GetHomeBaseUrl("Default.aspx"));
            }
   
            if (rInt > 0)
            {
                string OpTxt = string.Format("增加商业资讯成功!(ID:{0})", IDX);
                if (CMD == "Edit")
                    OpTxt = string.Format("修改商业资讯成功!(ID:{0})", IDX);
                EventMessage.MessageBox(1, "操作成功", OpTxt, Icon_Type.OK, Common.GetHomeBaseUrl("Default.aspx"));
            }
            else if (rInt == -2)
            {
                EventMessage.MessageBox(1, "操作失败", "操作失败,存在相同的键值(用户名/数据)!", Icon_Type.Alert, Common.GetHomeBaseUrl("Default.aspx"));
            }
            else
            {
                EventMessage.MessageBox(1, "操作失败", string.Format("操作失败,返回值:{0}!", rInt), Icon_Type.Error, Common.GetHomeBaseUrl("Default.aspx"));
            }
        }
    }
}
